<?php

/**
 * This is the model class for table "{{member}}".
 *
 * The followings are the available columns in table '{{member}}':
 * @property string $company_name
 * @property integer $show_company
 * @property string $first_name
 * @property string $middle_name
 * @property string $last_name
 * @property string $email
 * @property string $password
 * @property string $address
 * @property string $city
 * @property string $state
 * @property string $zip_code
 * @property string $country
 * @property integer $phone_number
 * @property integer $id
 */
class MemberModel extends CActiveRecord
{
    
    
                  
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return MemberModel the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{member}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('first_name, last_name, email, password, address, city, country, phone_number', 'required'),
			array('show_company, phone_number', 'numerical', 'integerOnly'=>true),
			array('company_name, email, city', 'length', 'max'=>30),
			array('first_name, middle_name, last_name, state, country', 'length', 'max'=>20),
			array('zip_code', 'length', 'max'=>10),
                                                     array('email','unique'),
                                                     array ('email','email'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('company_name, show_company, first_name, middle_name, last_name, email, password, address, city, state, zip_code, country, phone_number, id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'posts'=>array(self::HAS_MANY, 'PostModel', 'author_id'),
		);
                
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'company_name' => Yii::t('register', 'company_name'),
			'show_company' => Yii::t('register', 'company_show'),
			'first_name' => Yii::t('register', 'first_name'),
			'middle_name' => Yii::t('register', 'middle_name'),
			'last_name' => Yii::t('register', 'last_name'),
			'email' => Yii::t('register', 'email'),
			'password' => Yii::t('register', 'password'),
			'address' => Yii::t('register', 'address'),
			'city' => Yii::t('register', 'city'),
			'state' => Yii::t('register', 'state'),
			'zip_code' => Yii::t('register', 'zip_code'),
			'country' => Yii::t('register', 'country'),
			'phone_number' => Yii::t('register', 'phone_num'),
			'id' => Yii::t('register', 'member'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('company_name',$this->company_name,true);
		$criteria->compare('show_company',$this->show_company);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('middle_name',$this->middle_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('state',$this->state,true);
		$criteria->compare('zip_code',$this->zip_code,true);
		$criteria->compare('country',$this->country,true);
		$criteria->compare('phone_number',$this->phone_number);
		$criteria->compare('id',$this->id);
                
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
                        'pagination' => array(
                        'pageSize' => Common::getOptionValue('itemperpage','pagination'),
                    ),
		));
	}
}